Jon's Git Node
Commit 6492bb6b3b2d85def75cd948a7292699ce504b04
Parents : ff5e0c9
Author : Jonathan Lamothe <jonathan@jlamothe.net>
Date : 2026-09-18T16:08:38-04:00
modified page renderer to highlight selected text
Changes
Diff
diff --git a/nomadnet/ui/textui/MicronParser.py b/nomadnet/ui/textui/MicronParser.py
index 4f199db..1e0f99d 100644
--- a/nomadnet/ui/textui/MicronParser.py
+++ b/nomadnet/ui/textui/MicronParser.py
@@ -708,9 +708,43 @@ def left_indent(state):
def right_indent(state):
return (state["depth"]-1)*SECTION_INDENT
+def make_parts(state: dict, part: str) -> list:
+ """Render a string fragment into widgets"""
+ try:
+ search_text = state["search_text"]
+ except KeyError:
+ search_text = None
+ if not search_text:
+ return [make_part(state, part)]
+ search_text = search_text.lower()
+ parts = []
+ while len(part):
+ match part.lower().find(search_text):
+ case -1:
+ parts.append(make_part(state, part))
+ part = ''
+ case 0:
+ i = len(search_text)
+ sub = part[:i]
+ part = part[i:]
+ highlight_state(state)
+ parts.append(make_part(state, sub))
+ highlight_state(state)
+ case i:
+ sub = part[:i]
+ part = part[i:]
+ parts.append(make_part(state, sub))
+ return parts
+
def make_part(state, part):
return (make_style(state), part)
+def highlight_state(state: dict) -> None:
+ """Toggle styling attributes for search highlighting"""
+ state["formatting"]["bold"] ^= True
+ state["formatting"]["italic"] ^= True
+ state["formatting"]["underline"] ^= True
+
def state_to_style(state):
return { "fg": state["fg_color"], "bg": state["bg_color"], "bold": state["formatting"]["bold"], "underline": state["formatting"]["underline"], "italic": state["formatting"]["italic"] }
@@ -882,7 +916,7 @@ def make_output(state, line, url_delegate, pre_escape=False):
if state["literal"]:
if line == "\\`=":
line = "`="
- output.append(make_part(state, line))
+ output += make_parts(state, line)
else:
part = ""
mode = "text"
@@ -955,7 +989,7 @@ def make_output(state, line, url_delegate, pre_escape=False):
elif c == '<':
if len(part) > 0:
- output.append(make_part(state, part))
+ output += make_parts(state, part)
part = ""
try:
field_start = i + 1 # position after '<'
@@ -1087,7 +1121,7 @@ def make_output(state, line, url_delegate, pre_escape=False):
# First generate output until now
if len(part) > 0:
- output.append(make_part(state, part))
+ output += make_parts(state, part)
cm = nomadnet.NomadNetworkApp.get_shared_instance().ui.colormode
@@ -1114,11 +1148,11 @@ def make_output(state, line, url_delegate, pre_escape=False):
output.append((linkspec, link_label))
else:
- output.append(make_part(state, link_label))
+ output += make_parts(state, link_label)
mode = "text"
if len(part) > 0:
- output.append(make_part(state, part))
+ output += make_parts(state, part)
elif mode == "text":
if c == "\\":
@@ -1134,7 +1168,7 @@ def make_output(state, line, url_delegate, pre_escape=False):
else:
mode = "formatting"
if len(part) > 0:
- output.append(make_part(state, part))
+ output += make_parts(state, part)
part = ""
else:
part += c
@@ -1142,7 +1176,7 @@ def make_output(state, line, url_delegate, pre_escape=False):
if i == len(line)-1:
if len(part) > 0:
- output.append(make_part(state, part))
+ output += make_parts(state, part)
if len(output) > 0:
return output
Served by rngit 1.5.4 - Generated in 0.04s